<div class="page-add-new-article">
    <div id="content-header">
        <h1><?php echo __d('system','List Node Types');?></h1>
    </div>
    <div class="container-fluid">
    <div class="row-fluid">
        <div class="span12">
        <?php
            $data = $this->request->data;
            if(($data['NodeType']['set_menu']==1)||($data['NodeType']['menu_child']==1)){
                $dipslay = 'block';
            }else{$dipslay = 'none';}    
            echo $this->Form->create('NodeType', array('id' => 'paginate','class'=>'form-horizontal', 'action' => 'edit', 'url' => $this->request->here(false), 'type' => 'post',
                    'inputDefaults' => array('label' => false, 'format' => array('before', 'label', 'between', 'input', 'after', 'error'))));
            echo $this->element('toolbar');
        ?>									
                
        
            <?php 
                $fieldsets['name'] = $this->Form->input('name', array(
                        'label' => array('text'=>__d('system','Name'),'class' => 'control-label'),
                        'between' => '<div class="controls">',
                        'div' => array('class' => 'control-group'),
                        'after' => '</div>',
                        'type' => 'text'));
                $fieldsets['enabled'] = $this->Form->input('enabled', array(
                        'label' => array('text'=>__d('system','Menu Backend'),'class' => 'control-label'),
                        'between' => '<div class="controls">',
                        'div' => array('class' => 'control-group'),
                        'after' => '</div>',
                        'type' => 'checkbox'));
                $fieldsets['set_menu'] = $this->Form->input('set_menu', array(
                        'label' => array('text'=>__d('system','Show is menu'),'class' => 'control-label'),        
                        'between' => '<div class="controls">',
                        'div' => array('class' => 'control-group'),
                        'default'=>0,
                        'class'=>'set_menu', 
                        'after' => '</div>',
                        'type' => 'checkbox'));
                $fieldsets['allow_share'] = $this->Form->input('allow_share', array(
                        'label' => array('text'=>__d('system','Allow Share'),'class' => 'control-label'),        
                        'between' => '<div class="controls">',
                        'div' => array('class' => 'control-group'),
                        'default'=>0,                                            
                        'after' => '</div>',
                        'type' => 'checkbox'));
                $fieldsets['menu_child'] = $this->Form->input('menu_child', array(
                        'label' => array('text'=>'Sub Menu','class' => 'control-label'),        
                        'between' => '<div class="controls">',
                        'div' => array('class' => 'control-group'),
                        'default'=>0, 
                        'class'=>'set_menu',                                 
                        'after' => '</div>',
                        'type' => 'checkbox'));                                    
                $fieldsets['set_image'] = $this->Form->input('set_image', array(
                        'label' => array('text'=>__d('system','Show image'),'class' => 'control-label'),        
                        'between' => '<div class="controls">',
                        'div' => array('class' => 'control-group'),       
                        'after' => '</div>',
                        'type' => 'checkbox'));
                $fieldsets['description'] = $this->Form->input('description', array(
                        'label' => array('text'=>__d('system','Description'),'class' =>'control-label'),
                        'between' => '<div class="controls">',
                        'div' => array('class' => 'control-group'),
                        'after' => '</div>',
                        'type' => 'textarea'));                         
                $fieldsets['image'] = $this->Form->input('image', array(
                        'label' => array('text'=>__d('system','Image'),'class' => 'control-label'),
                        'between' => '<div class="controls">',
                        'div' => array('class' => 'control-group'),
                        'after' => '</div>',
                        'type' => 'file'));                    

            ?>        

            <?php
                echo $this->Layout->form($_layouts, $fieldsets);
            ?>
            <!--For add more gallery-->
            <div class="widget-box widget-content-no-padding">
                <div class="control-group">
                    <label for="NodeFieldProjectImage" class="control-label"><?php echo __d("system", "Image Relation")?></label>            
                    <div class="controls">
                        <?php echo $this->Form->input('ProImage', array(
                            'label' => false,
                            'type'  => 'file', 
                            'name' => 'data[ProImage][]'));?>
                    </div>
                    <div id="cloneImage"></div>
                    <a style="padding-left: 200px; clear: both;padding-bottom: 10px; display: block;" href="javascript:add_more();"><?php echo __d("system", "Add more image")?></a>
                </div>                 
            <!--End-->
            <!--For show list image-->
            <?php if(!empty($galleries)):?>            
                <?php 
                    foreach($galleries as $key=> $image):                        
                        if(!empty($image)):                        
                            $thumbnail_name = $image; 
                            endif;            
                    ?>
                    <span style="padding-top: 15px; display: block; float: left;">
                        <a id="image_<?php echo $key;?>" href=""><?php echo $this->Html->image($thumbnail_name, array('width'=>'100', 'height'=>'100', 'alt'=> 'Image','style'=>'width:100px !important;height:100px !important'));?></a>

                        <a id="image_del_<?php echo $key;?>" href="javascript:void(0);" onclick="delete_image('<?php echo $key?>');"><?php echo __d("system", "Delete")?></a>
                    </span>
                    <?php endforeach;?>                       
                <?php endif;?>
            <!--End-->
        	
        </div>    
            <input type="hidden" name="hd-id-node-type" id="hd-get-id-node-type" value="<?php echo $id;?>"/>
        <!--End-->
        <?php
            echo $this->Form->hidden('Paginate.task', array('id' => 'task', 'value' => ''));
            echo $this->Form->end();
        ?>        								
    </div>	
</div>
</div>
<script type="text/javascript">    
    function add_more(){
        var element= jQuery("#cloneImage").prev();
        jQuery(element).clone().insertBefore("#cloneImage");
        var $this = Green.Elfinder;
        jQuery('form input.file-upload').prop('readonly' , true).click(function(){
                $this.show(jQuery(this));
        });
    }
    function delete_image(id){
        if (confirm("Are you sure you want to delete?")) {
            var href= "<?php echo '/node/node/delete_image/'?>"+id;
            jQuery.ajax({
                    url: href,
                    type: "GET",
                    success: function(data) {           
                        jQuery('#image_'+id).remove();
                        jQuery('#image_del_'+id).remove();                       
                    }
            });
        }
    }
</script>